package cn.tmpan.util;


import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;
public class DateTimeUtil {

    //joda-time

    //str -> date
    //date ->str

    public static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:SS";


    public static Date srtToDate(String dateTime, String formatStr) {
        DateTimeFormatter dateTimeFormat = DateTimeFormat.forPattern(formatStr);
        DateTime dateTimes = dateTimeFormat.parseDateTime(dateTime);
        return dateTimes.toDate();

    }

    public static String dateToStr(Date date, String formatStr) {
        if (date == null) {
            return StringUtils.EMPTY;
        }
        DateTime dateTime = new DateTime(date);

        return dateTime.toString(formatStr);

    }


    public static Date srtToDate(String dateTime) {
        DateTimeFormatter dateTimeFormat = DateTimeFormat.forPattern(STANDARD_FORMAT);
        DateTime dateTimes = dateTimeFormat.parseDateTime(dateTime);
        return dateTimes.toDate();

    }

    public static String dateToStr(Date date) {
        if (date == null) {
            return StringUtils.EMPTY;
        }
        DateTime dateTime = new DateTime(date);

        return dateTime.toString(STANDARD_FORMAT);

    }


}

